package prog2012.practico3;

import java.util.Random;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestHashing {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		step3();
	}
	
	private void step1(){
		int tamanioTabla = 97;
		THashing hash = new THashing(tamanioTabla);
		int[] claves = new int[tamanioTabla];
		for (int i = 0; i < tamanioTabla; i++) {
			Random r = new Random();
			int clave = r.nextInt(Integer.MAX_VALUE) + 10000;
			int res = hash.insertarEnHash(clave);
			if (res == -1) { System.out.println("No Se inserto correctamente"); }
			else { System.out.println(clave + " " + res); }
			claves[i] = clave;
		}

		System.out.println("BUSCANDO CLAVES");
		for (int j = 0; j < claves.length; j++) {
			System.out.println("buscando (" + claves[j] + "): " + hash.buscarEnHash(claves[j]));
		}
	}
	
	private void step2(){
		int tamanioTabla = 97;
		THashing hash = new THashing(tamanioTabla);
		int[] claves = new int[tamanioTabla];
		for (int i = 0; i < tamanioTabla; i++) {
			Random r = new Random();
			int clave = r.nextInt(Integer.MAX_VALUE) + 10000;
			int res = hash.insertarEnHash(clave);
			if (res == -1) { System.out.println("No Se inserto correctamente"); }
			else { System.out.println(clave + " " + res); }
			claves[i] = clave;
		}
		
		String [] clavesString = new String[claves.length];
		
		for (int i = 0; i < clavesString.length; i++) {
			clavesString[i] = "" + claves[i];
		}
		ManejadorArchivosGenerico.escribirArchivo("C:\\Users\\kwiin\\Desktop\\BUSCAR.txt", clavesString);
	}
	
	private void step3(){
		int tamanioTabla = 97;
		THashing hash = new THashing(tamanioTabla);
		int[] claves = new int[tamanioTabla];
		hash.insertarDesdeArchivo("C:\\Users\\kwiin\\Desktop\\BUSCAR.txt");
		System.out.println("BUSCANDO CLAVES");
		for (int j = 0; j < tamanioTabla; j++) {
			System.out.println("buscando (" + claves[j] + "): " + hash.buscarEnHash(claves[j]));
		}
	}

}
